package org.chuan.org.service.impl;

import org.chuan.base.service.impl.BaseServiceImpl;
import org.chuan.org.domain.Employee;
import org.chuan.org.mapper.EmployeeMapper;
import org.chuan.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.regex.Pattern;


@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    // 邮箱验证
    private static final String EMAIL_PATTERN =
            "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
    private static final Pattern EMAIL_REGEX = Pattern.compile(EMAIL_PATTERN);

    @Override
    public Employee queryByUsername(String username) {
        return employeeMapper.queryByUsername(username);
    }

    @Override
    public List<Employee> querySelf(String username) {
        return employeeMapper.querySelf(username);
    }

    // 邮箱验证
    @Override
    public Boolean isValid(String email){
        return EMAIL_REGEX.matcher(email).matches();
    }


}
